package com.atguigu.hadoop.examples.mapreduce.wordStandardDeviation;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * 求和
 */
public class WordStandardDeviationReducer extends Reducer<Text, LongWritable, Text, LongWritable> {
    private LongWritable val = new LongWritable();

    public void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, LongWritable>.Context context)
            throws IOException, InterruptedException {
        int sum = 0;
        for (LongWritable value : values) {
            sum = (int) (sum + value.get());
        }
        this.val.set(sum);
        context.write(key, this.val);
    }

}
